package com.zygk.library.view;

import android.app.Dialog;
import android.content.Context;
import android.graphics.drawable.AnimationDrawable;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import com.zygk.library.R;

public class LoadingDialog extends Dialog {

  /**
   * 缓冲界面
   *
   * @param context
   */
  TextView loadingtext;
  ImageView ivLoading;
  AnimationDrawable animationDrawable;

  public LoadingDialog(Context context) {
    super(context, R.style.dialog_activity);
    View dialogView = getLayoutInflater().inflate(R.layout.library_dialog_loading, null);
    ivLoading = (ImageView) dialogView.findViewById(R.id.loading);
    loadingtext = (TextView) dialogView.findViewById(R.id.loading_text);
    ivLoading.setImageResource(R.drawable.loading_bg);
    setContentView(dialogView);
    animationDrawable = (AnimationDrawable) ivLoading.getDrawable();
    animationDrawable.start();
    setCanceledOnTouchOutside(true);
    setCancelable(true);
  }

  public void setMessageText(String messageText) {
    loadingtext.setText(messageText);
  }

  public void setLoadingBg(int resId) {
    animationDrawable.stop();
    ivLoading.setImageResource(resId);
    animationDrawable = (AnimationDrawable) ivLoading.getDrawable();
    animationDrawable.start();
  }
}
